package com.util;

import com.entity.Userinfo;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class RightInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		String actionName = actionInvocation.getProxy().getActionName();
		String methodName = actionInvocation.getProxy().getMethod();

		if ("users".equals(actionName)) {
			return actionInvocation.invoke();

		} else {
			Object obj = actionInvocation.getInvocationContext().getSession()
					.get("loginUser");
			if (obj == null) {
				return "login";
			} else {
				Userinfo users = (Userinfo)obj;
				String role = users.getUserType();
				if ("ϵͳ����Ա".equals(role)) {
					String result = actionInvocation.invoke();
					return result;
				} else {

					if ("show".equals(methodName)) {
						String result = actionInvocation.invoke();
						return result;
					} else {
						return "sorry";
					}
				}

			}
		}

	}

}
